my_list= ["lions", "tigers", "turtles", "leopard", "elephant", "dog", "tree monkey"]
def count_starting_letters(string_list, letter):
    count = 0
    for word in string_list:
        if word[0] == letter:
            count += 1
    return count
print(count_starting_letters(my_list,"t"))

def count_ending_letters(string_list, letter):
    count = 0
    for word in string_list:
        if word[-1] == letter:
            count += 1
    return count
print(count_ending_letters(my_list, "s"))
print(count_ending_letters(my_list, "y"))

def find_word(string_list, the_word):
    index = 0
    for word in string_list:
        if word == the_word:
            return index
        index += 1
    return -1
print(find_word(my_list, "leopard"))
print(find_word(my_list, "tiger"))

# Bubble sort
my_second_list = ["against", "forms", "belief", "government", "democratic", "movement", "understanding"]
def bubble_sort(string_list):
    swap_count = 0
    for i in range(len(string_list)):
        for j in range(len(string_list) - i - 1):
            if string_list[j] > string_list[j + 1]:
                temp = string_list[j]#switch the 2 strings
                string_list[j] = string_list[j + 1]
                string_list[j + 1] = temp
                swap_count += 1
    print("Bubble Sort Count:", swap_count)
    return string_list
print("Bubble Sorted List:", bubble_sort(my_second_list))

# Insertion Sort
my_third_list = ["against", "forms", "belief", "government", "democratic", "movement", "understanding"]
def insertion_sort(string_list):
    swap_count = 0
    for i in range(1, len(string_list)):#Start with the second element
        key = string_list[i]
        j = i - 1
        while j >= 0 and string_list[j] > key:
            string_list[j + 1] = string_list[j]#Move the element that is bigger than key to the right
            swap_count += 1
            j -= 1
        string_list[j + 1] = key
    print("Insertion Sort Count:", swap_count)
    return string_list
print("Insertion Sorted List:", insertion_sort(my_third_list))

